package org.corolla.cloth.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;

@ParentPackage(value = "struts-default")
@Results({
          @Result(name = "input", type = "redirect", location = "/view/Lining.jsp"),
          @Result(name = "success", type = "redirect", location = "/view/AccessoryChoose.jsp") })
@Namespace("/view")
@Action(value = "liningAction")
public class LiningAction extends ActionSupport {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private String            liningredioid;
    private String            Lining_name;
    private String            larghezza;

    @Override
    public String execute() throws Exception {
        // 程序运行到execute()时，前面的验证都已经正确了
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session = request.getSession();

        if (StringUtils.isNotBlank(this.getLining_name()) && StringUtils.isNotBlank(this.getLiningredioid())
            && StringUtils.isNotBlank(this.getLarghezza())) {
            
            String[] tmp = this.getLining_name().split("_");
            double liningPrice = Double.valueOf(tmp[tmp.length-1]);
            
            session.setAttribute("liningredioid", this.getLiningredioid());
            session.setAttribute("liningPrice", liningPrice);   //面料价格
            session.setAttribute("Lining_name", this.getLining_name());
            session.setAttribute("Lining", this.getLining_name().substring(0,this.getLining_name().indexOf("_")));
            session.setAttribute("larghezza", this.getLarghezza());
            return SUCCESS;
        }
        return "input";
    }

    public String getLiningredioid() {
        return liningredioid;
    }

    public void setLiningredioid(String liningredioid) {
        this.liningredioid = liningredioid;
    }

    public String getLining_name() {
        return Lining_name;
    }

    public void setLining_name(String lining_name) {
        Lining_name = lining_name;
    }

    public String getLarghezza() {
        return larghezza;
    }

    public void setLarghezza(String larghezza) {
        this.larghezza = larghezza;
    }

}
